package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.Dic;
import cn.wolfcode.crm.domain.Dicitem;
import cn.wolfcode.crm.mapper.DicMapper;
import cn.wolfcode.crm.mapper.DicitemMapper;
import cn.wolfcode.crm.query.DicitemQueryObject;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.IDicService;
import cn.wolfcode.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class DicService implements IDicService {
    @Autowired
    private DicMapper dicMapper;
    @Autowired
    private DicitemMapper dicitemMapper;


    public void changebyitemid(Long id) {
        dicitemMapper.changeByPrimaryKey(id);
    }

    public void changeByPrimaryKey(Long id) {
        dicMapper.changeByPrimaryKey(id);
        boolean state=dicMapper.getState(id);
        dicitemMapper.changebydicid(id,state);
    }

    public int insert(Dic entity) {
        return dicMapper.insert(entity);
    }

    public int insert(Dicitem entity) {
        return dicitemMapper.insert(entity);
    }

    public Dic selectByPrimaryKey(Long id) {
        return null;
    }

    public List<Dic> selectAll() {
        return null;
    }

    public int updateByPrimaryKey(Dic entity) {
        return dicMapper.updateByPrimaryKey(entity);
    }

    public int updateByPrimaryKey(Dicitem entity) {
        return dicitemMapper.updateByPrimaryKey(entity);
    }


    public PageResult query(QueryObject qo) {
        int total = dicMapper.query4Count(qo);
        if(total == 0 ){
            return new PageResult(0, Collections.EMPTY_LIST);
        }
        List<Dic> rows = dicMapper.query4List(qo);
        return new PageResult(total,rows);
    }



    public PageResult queryitem(DicitemQueryObject qo) {
        int total = dicitemMapper.query4Count(qo);
        if(total == 0 ){
            return new PageResult(0, Collections.EMPTY_LIST);
        }
        List<Dicitem> rows = dicitemMapper.query4List(qo);
        return new PageResult(total,rows);
    }

    @Override
    public List<Dicitem> selectItemBySn(String sn) {
        return dicitemMapper.selectItemBySn(sn);
    }



}
